package cn.loveq.android.util;

import java.lang.reflect.Type;
import java.util.ArrayList;

import org.json.JSONException;
import org.json.JSONObject;

import android.os.Message;

/**
 * 
 * 
 * 项目名称：loveq4Weibo 类名称：InformationDataLoader 类描述： 获取安全资讯获取器 创建人：李伟豪 创建时间：2011-12-6 下午07:21:46 修改人：Administrator 修改时间：2011-12-6 下午07:21:46 修改备注：
 * 
 * @version
 * 
 */

public class InformationDataLoader {
	private boolean isLoading = false;
	private int pageIndex;
	private int totalPage;
	private String condition;

	private String result;

	ILoadDataResponse responseInterface;

	public InformationDataLoader(ILoadDataResponse responseInterface) {
		this.responseInterface = responseInterface;
	}

	public boolean isLoading() {
		return isLoading;
	}

	public void loadNext(int index, int total, String conditionStr) {

		this.pageIndex = index;
		this.totalPage = total;
		this.condition = conditionStr;

		new Thread() {

			@Override
			public void run() {
				super.run();
				isLoading = true;
				try {
					if (totalPage == -1 || pageIndex <= totalPage) {
						// String url = ClientPreference.WEBURL_INFOMATION + "?pageInfo.pageIndex=" + pageIndex + "&condition=" + condition;
						// result = HttpRequest.getValueFromNet(url);
						// PageInfo pageInfo = parsePageInfoFromJson(result);
						// ArrayList<Addivieinfo> infos = null;
						// infos = parseListFromJson(result);
						Thread.sleep(1000);
						// responseInterface.onLoadDataComplete(infos, pageInfo.getTotalPage(), pageInfo.getPageIndex());
					} else {
						Thread.sleep(1000);
						responseInterface.onLoadDataError("没有更多的数据!");
					}
				} catch (Exception e) {
					e.printStackTrace();
					responseInterface.onLoadDataError("数据获取失败, 请稍候重试!");
				} finally {
					isLoading = false;
				}
			}

		}.start();
	}

}
